
#include "OgreApplication.h"


Console::Console(){
	this->layoutName = "Console.layout";

	this->load();
}

Console::~Console(){
}

void Console::handleInput(){

	Ogre::String text = this->getLineText();
	this->getConsoleEditbox()->setText("");
	
	this->append("No Console Handler initialized!");
}

CEGUI::Editbox* Console::getConsoleEditbox(){
		if(this->cegui_window == NULL)return NULL;	
		CEGUI::Editbox* box =(CEGUI::Editbox*) this->cegui_window->getChild("ConsoleEditbox/");
		return box;
}

CEGUI::MultiLineEditbox* Console::getConsoleField(){
		if(this->cegui_window == NULL)return NULL;
		CEGUI::MultiLineEditbox* box =(CEGUI::MultiLineEditbox*) this->cegui_window->getChild("ConsoleField/");
		return box;
}

Ogre::String Console::getLineText(){
		CEGUI::Editbox* help = this->getConsoleEditbox(); 
		
		if(help == NULL)return "";
	
	 return Ogre::String(help->getText().c_str()); 
}

Ogre::String Console::getText(){
	CEGUI::MultiLineEditbox* help = this->getConsoleField();
		
		if(help == NULL)return "";
	
	 return Ogre::String(help->getText().c_str()); 
}

void Console::setText(Ogre::String name) {

CEGUI::MultiLineEditbox* help = this->getConsoleField();
		
		if(help == NULL)return;

		help->setText("\n"+name);
}

void Console::append(Ogre::String name){
CEGUI::MultiLineEditbox* help = this->getConsoleField();
		
		if(help == NULL)return;

		Ogre::String help2 = this->getText()+"\n"+name;

		help->setText(help2);


}

void Console::setActive(){
	this->getConsoleEditbox()->activate();
}